package com.easyweb.generator.common.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @Description :
 * @FileName: PropKit.java
 * @Author :WeiHui.Zhang
 * @Data : 2016年3月3日 上午11:27:50
 * @Version:V1.00
 */
public class PropKit {

	private static Properties properties = null;

	public static void use(String fileName) {
		if (fileName == null || fileName.trim().length() == 0) {
			throw new RuntimeException("fileName can not be balank..");
		}
		InputStream inputStream = PropKit.class.getClassLoader().getResourceAsStream(fileName);
		if (inputStream == null) {
			throw new RuntimeException("file is not exist");
		} else {
			properties = new Properties();
			try {
				properties.load(inputStream);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static String get(String key) {
		if (properties == null) {
			throw new RuntimeException("Please apply PropKit.use(XXX) first..");
		}
		return properties.getProperty(key);
	}

}
